package yt.demo.appcorequartz.entity;

import com.baomidou.mybatisplus.annotation.TableField;
import com.baomidou.mybatisplus.annotation.TableId;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import lombok.Data;
import lombok.EqualsAndHashCode;
import yt.demo.appcommondb.base.BaseEntity;
import yt.demo.appcorequartz.enums.JobType;

import java.util.Objects;

@EqualsAndHashCode(callSuper = true)
@Data
public class QuartzJob extends BaseEntity<QuartzJob> {

    public static final String JOB_PARAM_KEY = "quartz_yt_dm_job";

    @TableId
    @Schema(name = "id", description = "主键ID")
    @NotNull(groups = UpdateGroup.class, message = "id不能为空")
    private Integer id;

    @Schema(description = "任务名称")
    @NotEmpty(groups = {CreateGroup.class,UpdateGroup.class},message = "任务名称不能为空")
    private String jobName;

    @Schema(description = "Bean名称")
    @NotEmpty(groups = {CreateGroup.class,UpdateGroup.class},message = "Bean名称不能为空")
    private String beanName;

    @Schema(description = "Cron表达式")
    @NotEmpty(groups = {CreateGroup.class,UpdateGroup.class},message = "Cron表达式不能为空")
    private String cronExpres;

    @Schema(description = "执行参数")
    private String params;

    @Schema(description = "任务状态：1正常，2暂停")
    private Integer status;

    @Schema(description = "任务类型")
    private Integer type;

    @Schema(description = "备注")
    private String remark;

    @TableField(exist = false)
    private String typeName;

    public String getTypeName() {
        return Objects.requireNonNull(JobType.fromType(getType())).getTypeName();
    }
}
